package org.taobao.ibatiside.ui.wizard;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelper;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;

public class ASTHelper extends ASTFacadeHelper {
	@Override
	public Map<?, ?> getJavaCoreOptions() {
		if (javaCoreOptions == null) {
			javaCoreOptions = createCLIJavaOptions();
		}
		return javaCoreOptions;
	}

	private Map<Object, String> createCLIJavaOptions() {
		Map<Object, String> tempCoreOptions = new HashMap<Object, String>();
		tempCoreOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);
		tempCoreOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
		tempCoreOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM,
				JavaCore.VERSION_1_6);
		tempCoreOptions.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER,
				JavaCore.ERROR);
		tempCoreOptions.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER,
				JavaCore.ERROR);
		tempCoreOptions.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE,
				JavaCore.ENABLED);
		tempCoreOptions.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT,
				JavaCore.ENABLED);
		tempCoreOptions.put("org.eclipse.jdt.core.incompleteClasspath",
				"warning");
		tempCoreOptions
				.put("org.eclipse.jdt.core.circularClasspath", "warning");
		//
		tempCoreOptions
				.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_ENUM_DECLARATION,
						DefaultCodeFormatterConstants.NEXT_LINE);
		tempCoreOptions
				.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_TYPE_DECLARATION,
						DefaultCodeFormatterConstants.NEXT_LINE);

		// separate fields with an empty line
		tempCoreOptions
				.put(DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_BEFORE_FIELD,
						"1");

		// make all enum constants to be on separate lines
		tempCoreOptions
				.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS,
						DefaultCodeFormatterConstants
								.createAlignmentValue(
										true,
										DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
										DefaultCodeFormatterConstants.INDENT_DEFAULT));
		return tempCoreOptions;
	}
}
